package com.service.impl;

import com.alibaba.druid.support.json.JSONUtils;
import com.dao.AccountDao;
import com.pojo.Account;
import com.service.AccountService;

public class AccountServiceImpl implements AccountService {

    AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    public void account(String inName, String toName, double money) {
        //查询账户
        //转出

        Account inAccount = accountDao.findByName(inName);

        //转入
        Account toAccount = accountDao.findByName(toName);


        //查询余额
        inAccount.setMoney(inAccount.getMoney() - money);
        toAccount.setMoney(toAccount.getMoney() + money);

        //更新
        accountDao.update(inAccount);
        System.out.println(1/0);
        accountDao.update(toAccount);
    }
}
